using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using CubeWars___Demolition.Services;


namespace CubeWars___Demolition.Controllers
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class viewController : Microsoft.Xna.Framework.GameComponent
    {
        Camera camera;
        TouchCollection currentTouches, oldTouches;

        public viewController(Game game)
            : base(game)
        {
            camera = game.Services.GetService(typeof(Camera)) as Camera;
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            currentTouches = TouchPanel.GetState();

            if (currentTouches.Count == 1 && oldTouches.Count == 1)
            {
                var deltaX = currentTouches[0].Position.X - oldTouches[0].Position.X;
                var deltaY = currentTouches[0].Position.Y - oldTouches[0].Position.Y;
                camera.Yaw += deltaX / 500;
                camera.Pitch += deltaY / 500;
            }

            oldTouches = TouchPanel.GetState();

            base.Update(gameTime);
        }
    }
}
